/**
 * @Author: colpu
 * @Date: 2025-03-29 17:57:34
 * @LastEditors: colpu ycg520520@qq.com
 * @LastEditTime: 2025-04-02 19:52:51
 * @
 * @Copyright (c) 2025 by colpu, All Rights Reserved.
 */
import shell from 'shelljs'; // 脚本执行
import _ from 'lodash';
import inquirer from 'inquirer';

/**
  @description 发布命令
  @cmd npm run shipit
*/
export default async function create(env, argv) {
  const otherArgv = argv.split(' ').splice(1);
  // 选择模式
  const choicesMap = {
    master: '网站开发模板，前后端同构开发',
    api: '微服务开发模板',
    exit: '退出'
  }
  const choices = Object.values(choicesMap)
  const branchs = Object.keys(choicesMap)
  const promptList = [{
    type: 'rawlist',
    message: '靠谱少年，请选择需要获取的模板: ',
    name: 'mode',
    choices
  }];
  const {
    mode
  } = await inquirer.prompt(promptList);
  const branch = branchs[choices.indexOf(mode)];
  const folder = otherArgv[0] || '';
  if (branch === 'exit') {
    shell.exit(0);
  }
  const bash = `git clone -b ${branch} git@gitee.com:ycg520520/colpu-example.git ${folder}`;
  shell.echo(bash);
  shell.exec(bash);
};
